import Vue from 'vue'
import Vuex from 'vuex'
import modules from './modules/index'
import getters from './getters'
Vue.use(Vuex)

const store = new Vuex.Store({
  modules,
  getters,
  actions: {
    resetState(context) {
      const types = Object.keys(context.rootState);
      const localStorageData = JSON.parse(JSON.stringify(localStorage));
      for (const k in localStorageData) {
        localStorage.removeItem(k);
      }

      types.forEach(item => {
        if (modules[item].mutations.resetState) {
          context.commit(`${item}/resetState`);
        }
      });
    },
  },
});

export default store;
